import store from "@/store/index.js"
import {checkRole} from "@/core/app.js"
import * as Role from "@/core/constant/role.js"

class HeartBeatData{
	 constructor(){
		this.userId = 0
		this.volunteerId = 0
		this.userPointX = 0
		this.userPointY = 0
		this.volunteerPointX = 0
		this.volunteerPointY = 0
		this.userStatus = 0
		this.volunteerStatus = 0
	}
	
	refreshData(data){
		this.refreshUserPosition()
		if(data === null){
			return
		}
		if(checkRole() === Role.ROLE_BLIND){
			this.userStatus = 1
			this.volunteerStatus = data.volunteerStatus ?? 0
			this.volunteerPointX = data.volunteerPointX ?? 0
			this.volunteerPointY = data.volunteerPointY ?? 0
		}else{
			this.userStatus = data.userStatus ?? 0
			this.volunteerStatus = 1
			this.userPointX = data.userPointX ?? 0
			this.userPointY = data.userPointY ?? 0
		}
	}
	
	refreshUserPosition(){
		const position = store.getters.userPosition
		if(checkRole() === Role.ROLE_BLIND){
			this.userPointX = position.pointX ?? 0
			this.userPointY = position.pointY ?? 0
		}else{
			this.volunteerPointX = position.pointX ?? 0
			this.volunteerPointY = position.pointY ?? 0
		}
	}
	
	
}


export default new HeartBeatData()